package com.szsfm.vehiclemanagement.http.okhttp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

/**
 * Created by zhoubigbo on 2017/11/3.
 *
 * okhttp cookie机制
 *
 */
public class OkhttpCookieJar implements CookieJar {

    private Map<HttpUrl, List<Cookie>> mCookieMap;

    @Override
    public List<Cookie> loadForRequest(HttpUrl url) {
        if (mCookieMap == null) return null;
        return mCookieMap.get(url);
    }

    @Override
    public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
        if (mCookieMap == null) {
            mCookieMap = new HashMap<>();
        }
        mCookieMap.put(url, cookies);
    }
}
